package com.cloud.example.business.flow.controller.parallel.worker;


import com.cloud.async.flow.callback.ICallback;
import com.cloud.async.flow.callback.IWorker;
import com.cloud.async.flow.util.timer.SystemClock;
import com.cloud.async.flow.worker.WorkResult;
import com.cloud.async.flow.wrapper.WorkerWrapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Map;

/**
 * @author chengrui
 */
public class ParWorker4 implements IWorker<String, String>, ICallback<String, String> {

    /**
     * logger
     */
    private final Log logger = LogFactory.getLog(getClass());


    @Override
    public String action(String object, Map<String, WorkerWrapper> allWrappers) {
        String result =  "ParWorker4 result = " + SystemClock.now() + "---param = " + object + " from ParWorker4";
        logger.info(result);
        return result;
    }

    @Override
    public String defaultValue() {
        return "ParWorker4--default";
    }

    @Override
    public void begin() {
    }

    @Override
    public void result(boolean success, String param, WorkResult<String> workResult) {
        String result =  "callback ParWorker4 " + (success == true ? "success" : "failure")
                + "--" + SystemClock.now() + "----" + workResult.getResult()
                + "-threadName:" +Thread.currentThread().getName();
        logger.info(result);
    }

}